home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
SAT 2.3.8
/
Demos
/
SAT Invaders demo ƒ
/
StarField.c
< prev
next >
Wrap
Text File
|
1995-11-09
|
2KB
|
93 lines
/* Starfield unit for SAT Invaders.
This unit uses the pixel array operations in SAT.
Richard Bannister deserves credits for making a similar improved SAT Invaders,
though using sprites for the stars. His demo convinced me that there should be
single pixel operations in SAT. */
#include <SAT.h>
#include <SATAddOnLib.h>
void InitStars();
void DoStars();
void ToggleStarField (Boolean starFieldFlag);
PixelPtr px=nil, pxcopy;
#define kNumPixels 100
#define Abs(x) (x>0?x:-x)
void InitStars()
{
short i;
px = (PixelPtr)NewPtrClear(sizeof(Pixel) * kNumPixels);
pxcopy = (PixelPtr)NewPtrClear(sizeof(Pixel) * kNumPixels);
for (i = 0; i< kNumPixels; i++)
{
px[i].data1 = 0;
px[i].data2 = SATRand(7) + 1;
px[i].position.h = SATRand(gSAT.offSizeH);
px[i].position.v = SATRand(gSAT.offSizeV);
}
} //InitStars
void ToggleStarField (Boolean starFieldFlag)
{
SATPort savePort;
if (starFieldFlag) {
SATGetPort(&savePort);
SATSetPortBackScreen();
ForeColor(blackColor);
PaintRect(&gSAT.backScreen.bounds);
CopyBits(&gSAT.backScreen.port->portBits, &gSAT.offScreen.port->portBits, &gSAT.backScreen.bounds, &gSAT.backScreen.bounds, srcCopy, nil);
SATRedraw();
SATSetPort(&savePort);
}
else
{
SATDrawPICTs(129, 128);
SATRedraw();
};
} //{ToggleStarField}
//The pixel set is processed with the assumption that all pixels move every frame.}
//They are drawn on top of the sprites.}
void DoStars()
{
short i;
if (px == nil)
InitStars();
BlockMove((Ptr)px, (Ptr)pxcopy, GetPtrSize((Ptr)px)); //{Make a copy}
for (i = 0; i< kNumPixels; i++)
{
px[i].position.h = px[i].position.h + px[i].data1;
px[i].position.v = px[i].position.v + px[i].data2;
if (px[i].position.h < 0)
{
px[i].position.h = 0;
px[i].data1 = Abs(px[i].data1);
};
if (px[i].position.v < 0)
{
px[i].position.v = 0;
px[i].data2 = Abs(px[i].data2);
};
if (px[i].position.h >= gSAT.offSizeH)
{
px[i].position.h = gSAT.offSizeH - 1;
px[i].data1 = -Abs(px[i].data1);
};
if (px[i].position.v >= gSAT.offSizeV)
{
px[i].position.v = 0;
};
};
SATDrawPixels(px, &gSAT.wind, 0xffffff00); //{Draw in new positions}
SATCopyPixels(pxcopy, &gSAT.offScreen, &gSAT.wind); //{Erase old positions}
} //{DoStars}